package com.jie.oss.controller;

import com.jie.commonutils.ResultEntity;
import com.jie.oss.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件上传的Controller类
 * @author XieZhiJie
 * @create 2020-10-07 13:24
 */
//@CrossOrigin  // 防止跨域问题
@RequestMapping("/eduoss/fileoss")
@RestController
public class OssController {

    private final OssService ossService;

    @Autowired
    public OssController(OssService ossService) {
        this.ossService = ossService;
    }

    // 上传头像的方法
    @PostMapping
    public ResultEntity uploadOssFile(
            MultipartFile file
    ) {
        // 获取上传的文件
        // 返回上传到oss的路径
        String url = ossService.uploadFileAvatar(file);
        return ResultEntity.ok().data("url", url);
    }

}
